﻿using UnityEngine;
using System.Collections;
using System;

namespace UI
{
    public class RecycleSelectTreasureItem : RecycleSelectItemBase , IComparable 
    {
        public CommonIcon icon;
        public UILabel nameLabel;
        public UILabel levelLabel;
        public UILabel refineLabel;

        UITreasure uiTreasure;

        protected override void SetData(object value)
        {
            UITreasure trea = value as UITreasure;
            uiTreasure = trea;
            icon.SetData(trea.treasureId, false);
            nameLabel.text = trea.name;
            levelLabel.text = TableTextBlo.GetText("level") + trea.strengthLevel;
            refineLabel.text = "" + trea.refineLevel;
        }

        public override string GetItemGUID()
        {
            return uiTreasure.guid; 
        }

        public UITreasure GetUITreasure()
        {
            return uiTreasure;
        }


        public int CompareTo(object obj)
        {
            RecycleSelectTreasureItem itemX = this; 
            RecycleSelectTreasureItem itemY = obj as RecycleSelectTreasureItem;
            UITreasure uiTreaX = itemX.GetUITreasure();
            UITreasure uiTreaY = itemY.GetUITreasure();

            if (uiTreaX.treasureData.quality > uiTreaY.treasureData.quality)
            {
                return 1;
            }
            else if (uiTreaX.treasureData.quality < uiTreaY.treasureData.quality)
            {
                return -1;
            }
            else
            {
                if (uiTreaX.refineLevel > uiTreaY.refineLevel)
                {
                    return 1;
                }
                else if (uiTreaX.refineLevel < uiTreaY.refineLevel)
                {
                    return -1;
                }
                else
                {
                    if (uiTreaX.strengthLevel > uiTreaY.strengthLevel)
                    {
                        return 1;
                    }
                    else if (uiTreaX.strengthLevel < uiTreaY.strengthLevel)
                    {
                        return -1;
                    }
                    else
                    {
                        return uiTreaX.treasureId.CompareTo(uiTreaY.treasureId);
                    }
                }
            }
        }
    }
}